#!/bin/csh -f

if ( $#argv == 0 ) then
	echo hoedown some/file/to/backup
	exit 1
endif

set CURRENTDIR = `pwd`
set ROOT = /home/yangdw/code/hoedown/CompRoot
set LIST = /home/yangdw/code/hoedown/hoedown.list

set HAS_SLASH = "`echo $1 | grep -o '/' `"
if ( "$HAS_SLASH" != "" ) then
	set DIR = "`echo $1 | sed -e 's/\(.*\/\)\(.*\)/\1/' `"
	set FILE = "`echo $1 | sed -e 's/\(.*\/\)\(.*\)/\2/' `"
	cd $DIR
	if ( "$?" != "0" ) then
		exit 1
	endif
else
	set FILE = "$1"
endif
	
set DIRFULL = "`pwd`"
if ( ! -d "${ROOT}${DIRFULL}" ) then
	mkdir -p ${ROOT}${DIRFULL}
endif
cp -Rf $FILE ${ROOT}${DIRFULL}/${FILE}
echo ${DIRFULL}/${FILE} >> $LIST

cd $CURRENTDIR

exit 0
